<?php echo css_url("design"); 
echo css_url('jquery-ui.min');
echo js_url("jquery-ui.min");
echo css_url("jquery-ui.theme.min");
echo css_url("jquery-ui.structure.min");
?>

<div class="container">
	<div class="bg-white">
		<div class="row">
			<h1><center> Gantt du projet </center></h1>
		</div>
		<div class="row">
			<div class="col-md-4">
				<select id="filtrageRessource">
					<option value="ressource1">Filtrer pour une ressource</option>
				</select>
			</div>
			<div class="col-md-2">
				<span><?php echo $leGroupe[0]->GRP_LIB; ?></span>
			</div>
			<div class="col-md-4">
				<div class="progress">
					<div class="progress-bar" role="progressbar" aria-valuenow="42" aria-valuemin="0" aria-valuemax="100" style="width: 42%;">
						<span class="sr-only">42%</span>
					</div>
				</div>
			</div>

			<div class="col-md-2">
				<button type="button" class="btn btn-default addTache">Ajouter une tâche</button>
			</div>
		</div>

		<div class="row">
			<div class="col-md-12">
				<table class="table table-striped">
					<thead>
						<tr>
							<td>Tache</td>
							<td>Heure d&eacute;but</td>
							<td>Heure fin</td>
							<td>20H</td>
							<td>21H</td>
							<td>22H</td>
							<td>23H</td>
							<td>00H</td>
							<td>01H</td>
							<td>02H</td>
							<td>03H</td>
							<td>04H</td>
							<td>05H</td>
							<td>06H</td>
							<td>07H</td>
							<td>08H</td>
							<td colspan="4">Actions</td>
						</tr>
					</thead>
					<tbody>
						<?php
						foreach ($lesTaches as $uneTache) {
							$dateD = $uneTache->TSK_start_hour_plan;
							$dateD = explode(" ", $dateD);
							$dateE = $uneTache->TSK_end_hour_plan;
							$dateE = explode(" ", $dateE);
							echo '
							<tr class="ligne">
								<td>'.$uneTache->TSK_LIB.'</td>
								<td class="start">'.$dateD[1].'</td>
								<td class="end">'.$dateE[1].'</td>
								<td class="20:00:00"></td>
								<td class="21:00:00"></td>
								<td class="22:00:00"></td>
								<td class="23:00:00"></td>
								<td class="00:00:00"></td>
								<td class="01:00:00"></td>
								<td class="02:00:00"></td>
								<td class="03:00:00"></td>
								<td class="04:00:00"></td>
								<td class="05:00:00"></td>
								<td class="06:00:00"></td>
								<td class="07:00:00"></td>
								<td class="08:00:00"></td>
								<td>';
									if ($uneTache->TSK_isNP == 1) { echo "(NP)"; }
									echo '</td>
									<td><a  href="'.base_url().'utilisateur/modifTask/'.$uneTache->PK_TSK.'" id="edit'.$uneTache->PK_TSK.'"><span class="glyphicon glyphicon-edit"></span></a></td>
									<td><a href="'.base_url().'utilisateur/deleteTask/'.$uneTache->PK_TSK.'" id="delete'.$uneTache->PK_TSK.'"<span class="glyphicon glyphicon-remove-circle"></span></td>
									<td><span></span></td>
								</tr>
								';
							}
							?>
						</tbody>
					</table>
				</div>

				<div class="formCreateTask">
					<div class="center">
						<h4>Ajouter une tache</h4>
						<form class="form-horizontal" method=post action="<?php echo base_url() ?>utilisateur/addTask">
							<label>Nom de la tache</label>
							<input type="text" name="TSK_LIB" class="form-control"/>
							<br />

							<label>Ressource</label>
							<select name="FK_USR" class="form-control">
								<?php
								foreach ($lesUsers as $value){
									echo" <option value='".$value->PK_USR."'>".$value->USR_name."</option>";
								};
								?>
							</select> 
							<br />

							<label>Item projet</label>
							<select name="FK_ITM" class="form-control">
								<?php
								foreach ($lesItems as $value){
									echo" <option value='".$value->PK_ITM."'>".$value->ITM_LIB."</option>";
								};
								?>
							</select> 
							<br />

							<label>De : </label>
							<input type="time" name="TSK_start_hour_plan" class="form-control"><br />

							<label>&agrave; : </label>
							<input type="time" name="TSK_end_hour_plan" class="form-control"><br />
							<input type="submit" value="Valider" class="form-control"><br />
							<button class="btn btn-default fermer" onClick="return false;	">Fermer</button>
						</form>
					</div>
				</div>
			</div>
		</div>
	</body>

	<script>
		$(document).ready(function() {
			$(".addTache").on('click', function() {
				$('div.formCreateTask').show();
			});
			$(".fermer").on('click', function(e) {
				e.preventDefault();
				$("div.formCreateTask").hide();
			})

			var start = $(".start").text();
			var end = $(".end").text();
			if (start == "00:00:00") {
				start = "24:00:00";
			}
			if (end == "00:00:00") {
				end = "24:00:00";
			}
			var delta = parseInt(end) - parseInt(start);
			
			$(".ligne>td").each(function() {
				if ($(this).hasClass(start))
				{
					$(this).css("background-color", "black");					
					if ($(this).next().attr("class") <= end) {
						$(this).next().css("background-color", "black");
						$(this).next().next().css("background-color", "black");
					}
				}
			});
			
			$(".datepicker").datepicker({
				timeFormat:  "HH:mm"
			});


			
		});
	</script>